home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
gsdbloo.exe
/
GS_DBFLD.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-02-27
|
50KB
|
1,482 lines
{ dBase III Field Handler
GS_DBFLD Copyright (c) Richard F. Griffin
15 November 1990
102 Molded Stone Pl
Warner Robins, GA 31088
-------------------------------------------------------------
This unit handles field processing for all dBase III file (.DBF)
operations.
SHAREWARE -- COMMERCIAL USE RESTRICTED
Changes:
02 May 91 - Changed the type of value returned for a date field from
string to longint. The value assigned is the julian date.
Note that the Julian day number is not the same as the
serial day number (1-366) which is sometimes (erroneously)
called a Julian date. Refer to the GS_Date unit for more
information.
03 May 91 - Ensured Date field is a julian date for .NDX indexes in the
IndexTo method.
02 Jun 91 - Allowed a 'blank' date field to be acccepted if the field
was originally blank in AcceptField.
31 Jul 91 - Created a StatusUpdate virtual method to allow a user to
track progress of actions such as Pack and IndexTo. The
status will be passed to StatusUpdate from within those
methods. The basic StatusUpdate is empty and does nothing
with the passed status. The user has the option to create
his own virtual method to capture this information.
20 Oct 91 - Added a Zap method to delete and remove all records.
20 Oct 91 - Corrected the Pack Method to write the EOF Mark in the
proper location.
11 Nov 91 - Corrected IndexTo problem with garbage object data.
Added close and init calls to ensure good object.
20 Feb 92 - Added a Done destructor to allow dynamic allocation
of objects.
Added GSP_dBFld_Objct as pointer type to the object.
This facilitates dynamic creation of the object.
------------------------------------------------------------------------------}
{
┌──────────────────────┐
│ INTERFACE SECTION: │
└──────────────────────┘
}
unit GS_dBFld;
{$D-}
interface
uses
CRT,
GS_Date,
GS_Edit,
GS_FileH,
GS_Error,
GS_KeyI,
GS_Strng,
GS_Winfc,
GS_dBase;
const
StatusStart = -1;
StatusStop = 0;
StatusIndexTo = 1;
StatusPack = 2;
type
GSP_dBFld_Objt = ^GS_dBFld_Objt;
GS_dBFld_Objt = object(GS_dBase_dB)
LastFldTyp : char; {Last FieldGet type field}
LastFldDec : integer; {Last FieldGet Decimals}
LastFldLth : integer; {Last FieldGet Length}
LastFldNam : string[11]; {Last FieldGet Name}
LastFldNum : integer; {Last FieldGet Number}
EditOn : boolean; {Edit allowed}
RecChanged : boolean; {Flag for record changed}
Memo_Loc : longint; {Starting memo block for field}
Memo_Bloks : integer; {Number of blocks used for the field}
Memo_Store : GS_Edit_Objt; {Object to store/edit memos}
DeleteOnF9 : boolean; {Flag to permit F9 to delete/undelete}
Constructor Init(FName : string);
Destructor Done;
Procedure Check_Func_Keys; virtual;
Function Create(FName : string) : boolean;
function DateGet(st : string) : longint;
function DateGetN(n : integer) : longint;
Procedure DatePut(st : string; jdte : longint);
Procedure DatePutN(n : integer; jdte : longint);
Function FieldAccept(st,Titl : string; x,y : integer) : string;
Procedure FieldDisplay(st,Titl : string; x,y : integer);
Function FieldDisplayScreen : boolean;
Function FieldGet(st : string) : string;
Function FieldGetN(n : integer) : string;
Procedure FieldPut(st1, st2 : string);
Procedure FieldPutN(n : integer; st1 : string);
Function FieldUpdateScreen : boolean;
Function FieldAppendScreen(empty : boolean) : boolean;
Function Formula(st : string; var ftyp : char) : string; virtual;
Function HuntFieldName(st : string; var fs : integer) : boolean;
Procedure IndexTo(filname, formla : string);
function LogicGet(st : string) : boolean;
function LogicGetN(n : integer) : boolean;
Procedure LogicPut(st : string; b : boolean);
Procedure LogicPutN(n : integer; b : boolean);
Procedure MemoEdit;
function MemoGetLine(linenum : integer) : string;
procedure MemoGet(rpt : string);
Procedure MemoWidth(l : integer);
function MemoLines : integer;
function MemoPut : string;
function NumberGet(st : string) : real;
function NumberGetN(n : integer) : real;
Procedure NumberPut(st : string; r : real);
Procedure NumberPutN(n : integer; r : real);
Procedure Pack;
Procedure StatusUpdate(statword1,statword2,statword3 : longint); virtual;
function StringGet(st : string) : string;
function StringGetN(n : integer) : string;
Procedure StringPut(st1, st2 : string);
Procedure StringPutN(n : integer; st1 : string);
Procedure Zap;
end;
implementation
constructor GS_dBFld_Objt.Init(FName : string);
begin
EditOn := true;
GS_dBase_DB.Init(FName);
Memo_Store.Init; {Initialize the edit object}
Memo_Store.Edit_Lgth := 50; {Set default memo line size to 50}
Wait_Cr := false; {Set EditString not to wait for CR}
DeleteOnF9 := false; {Turn off F9 for delete/undelete}
end;
destructor GS_dBFld_Objt.Done;
begin
Memo_Store.Done;
GS_dBase_DB.UnInit;
end;
procedure GS_dBFld_Objt.Check_Func_Keys;
begin
case ch of
Kbd_F9 : begin
if DeleteOnF9 then
begin
if RecNumber < 0 then
begin
if DelFlag then CurRecord^[0] := 32
else CurRecord^[0] := 42;
DelFlag := not DelFlag;
end
else if DelFlag then UnDelete else Delete;
GS_KeyI_Ret := true;
Ch := Kbd_Ret;
end else GS_dBase_DB.Check_Func_Keys;
end;
Kbd_F10 : begin
GS_KeyI_Ret := true;
Ch := Kbd_Ret;
end;
else GS_dBase_DB.Check_Func_Keys;
end;
end;
function GS_dBFld_Objt.DateGet(st : string) : longint;
var
t : string;
v : longint;
begin
t := FieldGet(st);
v := GS_Date_Juln(t);
if v > 0 then DateGet := v else DateGet := 0;
end;
function GS_dBFld_Objt.DateGetN(n : integer) : longint;
var
t : string;
v : longint;
begin
t := FieldGetN(n);
v := GS_Date_Juln(t);
if v > 0 then DateGetN := v else DateGetN := 0;
end;
Procedure GS_dBFld_Objt.DatePut(st : string; jdte : longint);
var
f : integer;
t : string[8];
begin
if not HuntFieldName(st,f) then
begin
ShowError(625,st);
exit;
end;
if jdte = 0 then t := ' '
else t := GS_Date_DBStor(jdte);
FieldPutN(f,t);
end;
Procedure GS_dBFld_Objt.DatePutN(n : integer; jdte : longint);
var
t : string[8];
begin
if n > NumFields then
begin
ShowError(627,'Field number out of range');
exit;
end;
if jdte = 0 then t := ' '
else t := GS_Date_DBStor(jdte);
FieldPutN(n,t);
end;
function GS_dBFld_Objt.LogicGet(st : string) : boolean;
begin
LogicGet := ValLogic(FieldGet(st));
end;
function GS_dBFld_Objt.LogicGetN(n : integer) : boolean;
begin
LogicGetN := ValLogic(FieldGetN(n));
end;
Procedure GS_